package top.fengleifeng.question;

import java.util.Arrays;

/**
 * @program: leetcode-test
 * @description:
 * @author: fengleifeng
 * @create: 2020-10-09 12:02
 **/
public class Num945使数组唯一的最小增量 {
    /**
     * 思路：
     * 排序：
     */
    class Solution {
        public int minIncrementForUnique(int[] A) {
            if (A.length <= 0) {
                return 0;
            }
            Arrays.sort(A);
            int max = A[0];
            int count = 0;
            for (int i = 1; i < A.length; i++) {
                if (max >= A[i]) {
                    max ++;
                    count += max - A[i];
                    A[i] = max;
                } else {
                    max = A[i];
                }
            }
            return count;
        }
    }

    public static void main(String[] args) {
        int[] ints = {3,2,1,2,1,7};
        int i = new Num945使数组唯一的最小增量().new Solution().minIncrementForUnique(ints);

        System.out.println(i);
    }
}
